<?php
	
	include('../classes/clsDB.php');
	
	include('../config.inc.php');
	$r=new ReturnRecord();
	
	
	$SQL="SELECT LCommission FROM affiliatePrograms,affiliateJoinedPrograms WHERE affiliatePrograms.id=$_GET[ap] AND affiliateJoinedPrograms.affiliateID=$_COOKIE[AffCode] AND affiliatePrograms.id=affiliateJoinedPrograms.affiliateProgramsID";
	//print $SQL;
	$sq2=$r->rawQuery($SQL);  
	$myrow = mysql_fetch_row($sq2);
	
	
	if($myrow[0]>0){
		$SQL="SELECT COUNT(*) FROM affiliateLeads WHERE VisitsID='$_COOKIE[AffSid]' ";
		$sq2=$r->rawQuery($SQL); 
		$data=mysql_fetch_array($sq2);
		if($data[0]==0){ 
			$SQL="INSERT INTO affiliateEarn (affiliateProgramsID,affiliateID,CommissionAmount,VisitsID,EDateTime,EType) VALUES ($_GET[ap],$_COOKIE[AffCode],$myrow[0],$_COOKIE[AffSid],NOW(),'Lead') ";
//print $SQL;
			$sq2=$r->rawQuery($SQL);
			$SQL="UPDATE affiliate SET Account=Account+$myrow[0] WHERE id=$_COOKIE[AffCode]";
			$sq2=$r->rawQuery($SQL);
		}  
	}
	
?>
